package com.core.model.xg;

import com.core.dto.RefrigerationDTO;
import com.core.model.AbstractEntity;

import javax.persistence.*;

/**
 * Created with IntelliJ IDEA.
 *
 * @author lxf
 * @date 2018/5/2 16:43
 * To change this template use Editor | File and Code Templates.
 */
@Entity
@Table(name = "refrigeration")
public class Refrigeration extends AbstractEntity {

    /**
     * 项目日期
     */
    private String date;
    /**
     * 项目名称
     */
    private String project;
    /**
     * 收入
     */
    private double income;
    /**
     * 支出
     */
    private double expenditure;
    /**
     * 项目执行者
     */
    @ManyToOne(cascade = {CascadeType.MERGE, CascadeType.REFRESH}, optional = false)
    @JoinColumn(name = "executor_id")
    private Excutor excutor;

    public Refrigeration() {
    }

    public Refrigeration(String date, String project, double income, double expenditure, Excutor excutor) {
        this.date = date;
        this.project = project;
        this.income = income;
        this.expenditure = expenditure;
        this.excutor = excutor;
    }

    public void init(RefrigerationDTO refrigerationDTO, Excutor excutor) {
        this.date = refrigerationDTO.getDate();
        this.project = refrigerationDTO.getProject();
        this.income = Double.parseDouble(refrigerationDTO.getIncome());
        this.expenditure = Double.parseDouble(refrigerationDTO.getExpenditure());
        this.excutor = excutor;
    }


    public String date() {
        return date;
    }

    public String project() {
        return project;
    }

    public double income() {
        return income;
    }

    public double expenditure() {
        return expenditure;
    }

    public Excutor excutor() {
        return excutor;
    }
}
